/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package co.edu.uniminuto.arqSw.ejercicio.DAO;

import co.edu.uniminuto.arqSw.ejercicio.Hibernate.HibernateUtil;
import co.edu.uniminuto.arqSw.ejercicio.Hibernate.Persona;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author diegoalejandro
 */
public class PersonaDAO {
    
    private Session sesion=null;

    public PersonaDAO() {
        this.sesion = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List<Persona> getPersonas(){
        List<Persona> misPersonas= new ArrayList<Persona>();
        
        try {
            Transaction tx = this.sesion.beginTransaction();
            Query query=this.sesion.createQuery("From Persona");
            misPersonas = (List<Persona>) query.list();
        } catch (Exception e) {
            e.printStackTrace();    
        }
        return misPersonas;
    }
    
   
    public List<Persona> getTelefonos(){
        List<Persona> misTelefonos= new ArrayList<Persona>();
        
        try {
            Transaction tx = this.sesion.beginTransaction();
            Query query=this.sesion.createQuery("From Telefono");
            misTelefonos = (List<Persona>) query.list();
        } catch (Exception e) {
            e.printStackTrace();    
        }
        return misTelefonos;
    }
}
